const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap: false,  // 关闭 .map 文件
  publicPath: './',
  configureWebpack: {
    optimization: {
      splitChunks: {
        chunks: 'all',
        minSize: 10000,  // 10KB 以上才拆分
        maxSize: 100000, // 尽量让每个 chunk ≤100KB（但大依赖包不受限）
        cacheGroups: {
          vendors: {
            test: /[\\/]node_modules[\\/]/,
            name: 'chunk-vendors',
            priority: -10,
            chunks: 'initial'
          },
          common: {
            minChunks: 2,
            name: 'chunk-common',
            priority: -20,
            reuseExistingChunk: true
          }
        }
      }
    }
  },
  devServer: {
    proxy: {
      '/api': {
        target: 'http://192.168.0.189:8080',
        changeOrigin: true,
        pathRewrite: { '^/api': '' },
        headers: {
          'Access-Control-Allow-Origin': 'http://localhost:8080',
          'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
          'Access-Control-Allow-Headers': 'Content-Type, Authorization',
        },
      },
    },
  }
})